package com.lineage.data.cmd;

import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.datatables.lock.CharSkillReading;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_AddSkill;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Skills;

public class Skill_Studying implements Skill_StudyingExecutor {
  public void magic(L1PcInstance pc, int skillId, int magicAtt, int attribute, int itemObj) {
    int pclvl = pc.getLevel();
    boolean isUse = true;
    if (pc.isCrown()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 1:
          if (pclvl >= 10) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 2:
          if (pclvl >= 20) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 21:
          if (pclvl >= 15) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 22:
          if (pclvl >= 30) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 23:
          if (pclvl >= 40) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 24:
          if (pclvl >= 45) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 25:
          if (pclvl >= 50) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 26:
          if (pclvl >= 55) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } else if (pc.isKnight()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 1:
          if (pclvl >= 50) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 31:
          if (pclvl >= 50) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 32:
          if (pclvl >= 60) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } else if (pc.isWizard()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 1:
          if (pclvl >= 4) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 2:
          if (pclvl >= 8) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 3:
          if (pclvl >= 12) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 4:
          if (pclvl >= 16) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 5:
          if (pclvl >= 20) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 6:
          if (pclvl >= 24) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 7:
          if (pclvl >= 28) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 8:
          if (pclvl >= 32) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 9:
          if (pclvl >= 36) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 10:
          if (pclvl >= 40) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } else if (pc.isElf()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 1:
          if (pclvl >= 8) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 2:
          if (pclvl >= 16) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 3:
          if (pclvl >= 24) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 4:
          if (pclvl >= 32) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 5:
          if (pclvl >= 40) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 6:
          if (pclvl >= 48) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 11:
          if (pclvl >= 10) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 12:
          if (pclvl >= 20) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 13:
          if (pclvl >= 30) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 14:
          if (pclvl >= 40) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 15:
          if (pclvl >= 50) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } else if (pc.isDarkelf()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 1:
          if (pclvl >= 12) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 2:
          if (pclvl >= 24) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 41:
          if (pclvl >= 15) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 42:
          if (pclvl >= 30) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 43:
          if (pclvl >= 45) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 44:
          if (pclvl >= 60) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } else if (pc.isDragonKnight()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 51:
          if (pclvl >= 15) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 52:
          if (pclvl >= 30) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 53:
          if (pclvl >= 45) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } else if (pc.isIllusionist()) {
      S_ServerMessage msg;
      switch (magicAtt) {
        case 61:
          if (pclvl >= 10) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 62:
          if (pclvl >= 20) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 63:
          if (pclvl >= 30) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        case 64:
          if (pclvl >= 40) {
            mapPosition(pc, skillId, attribute, itemObj);
            break;
          } 
          isUse = false;
          break;
        default:
          msg = new S_ServerMessage(79);
          pc.sendPackets((ServerBasePacket)msg);
          break;
      } 
    } 
    if (!isUse) {
      S_ServerMessage msg = new S_ServerMessage(312);
      pc.sendPackets((ServerBasePacket)msg);
    } 
  }
  
  private void mapPosition(L1PcInstance pc, int skillId, int attribute, int itemObj) {
    boolean isOk = false;
    spellBook(pc, skillId, itemObj);
  }
  
  private void spellBook(L1PcInstance pc, int skillId, int itemObj) {
    pc.getInventory().removeItem(pc.getInventory().getItem(itemObj), 1L);
    pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, skillId));
    char c = 'a';
    S_SkillSound sound = new S_SkillSound(pc.getId(), 227);
    pc.sendPacketsX8((ServerBasePacket)sound);
    L1Skills skill = SkillsTable.get().getTemplate(skillId);
    String skillName = skill.getName();
    CharSkillReading.get().spellMastery(pc.getId(), skillId, skillName, 0, 0);
  }
}
